package com.example.feedback.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.feedback.R;
import com.example.feedback.service.entity.ReplyBean;

import java.util.List;

/**
 * 反馈回复适配器
 */
public class ReplyAdapter extends RecyclerView.Adapter<ReplyAdapter.ViewHolder> {
    private List<ReplyBean> data;

    public void setData(List<ReplyBean> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    private ReplyBean replyBean;
    public ReplyAdapter(List<ReplyBean> data) {
        this.data = data;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.feed_reply_item_left, viewGroup,false);
        View view2 = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.feed_reply_item_right, viewGroup,false);
        return new ViewHolder(ReplyBean.LEFT == i ? view : view2);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
        replyBean = data.get(i);
        viewHolder.tvTime.setText(replyBean.getAddtime());
        viewHolder.tvContent.setText(replyBean.getDescribe());
    }

    @Override
    public int getItemViewType(int position) {
        return data.get(position).getType();
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvTime;
        TextView tvContent;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvTime = itemView.findViewById(R.id.tv_time);
            tvContent = itemView.findViewById(R.id.tv_content);
        }
    }
}
